package com.mhxy.service.impl;

import com.mhxy.constant.PicConstants;
import com.mhxy.service.AbstractTask;
import com.mhxy.util.FuzzyPicUtil;
import com.mhxy.util.ThreadUtil;
import com.mhxy.util.TimeUtil;
import com.sun.jna.platform.win32.WinDef;
import lombok.extern.slf4j.Slf4j;

/**
 * 三界奇缘任务
 */
@Slf4j
public class AQTaskmpl extends AbstractTask {

    public AQTaskmpl(WinDef.HWND hwnd_0) {
        super(hwnd_0);
    }

    @Override
    public String getTaskName() throws Exception {
        return "三界奇缘";
    }

    @Override
    public Boolean before() throws Exception {
        clickEsc3();
        // 找到活动并打开
        if (FuzzyPicUtil.findPic(hwnd_0, PicConstants.公共_活动, 2).isFinded()) {
            return true;
        }
        return goToJianYe();
    }

    @Override
    public Boolean execute() throws Exception {
        // 判断时间是否为11:00~24:00
        if (!TimeUtil.between(11, 23)) {
            log.info("【{}】未在活动时间！", getTaskName());
            return false;
        }
        // 找到“日常活动”并打开
        if (!findAndClickActivity()) {
            return false;
        }

        // 找到任务并参加
        Boolean canYuRes = findAndClickTaskTitle(PicConstants.三界奇缘_任务图标标题, PicConstants.三界奇缘_完成图标);
        if (canYuRes == null || !canYuRes) {
            return canYuRes;
        }

        // 循环答题
        for (int i = 0; i < 20; i++) {
            // 点击答题
            FuzzyPicUtil.findAndClickRandom(hwnd_0, PicConstants.三界奇缘_答题标志, 1);
            ThreadUtil.sleep1();
            if (i >= 10) {
                if (FuzzyPicUtil.findPic(hwnd_0, PicConstants.三界奇缘_结束标志, 1).isFinded()) {
                    break;
                }
            }
        }

        return true;
    }

    @Override
    public Boolean after() throws Exception {
        clickEsc3();
        clickUse(2);
        return true;
    }
}
